package com.itbour.web.action.stats;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.itbour.com.page.Page;
import com.itbour.common.base.BaseAction;
import com.itbour.common.util.StringUtils;
import com.itbour.dto.com.UserInfoDto;
import com.itbour.service.stats.OrderStatsService;
import com.opensymphony.xwork2.ActionContext;

public class GetOrderStatsAction extends BaseAction {
	
	private OrderStatsService orderStatsService;
	private static final long serialVersionUID = 1L;
	private String findDateStart;// 检索条件[时间范围(起始)]
	private String findDateEnd;// 检索条件[时间范围(截止)]
	HashMap<String, Object> mapResult = new HashMap<String, Object>();// 检索查询出来的结果
	private String findOrderDate;// 检索条件[统计方式]
	private String findOrderType;// 检索条件[订单类型]
	private String findPayPlt;// 支付平台
	private String findPayFrom;// 支付来源
	
	public String getOrderCntListinfo() throws Exception{
		// 用户信息
		Map<String, Object> session = ActionContext.getContext().getSession();
		UserInfoDto user = (UserInfoDto)session.get("user");
		if(user!=null && user.getUser_id()!=null) {
			HttpServletRequest request = ServletActionContext.getRequest();
			String pageNumber = request.getParameter("page");
			String pageSize = request.getParameter("rows");
			Map<String, Object> param = new HashMap<String, Object>();
			if(StringUtils.isNotBlank(findOrderDate)&&Long.valueOf(findOrderDate)>0L){
				param.put("findOdt", findOrderDate);
			}
			if (StringUtils.isNotBlank(findDateStart)) {
				param.put("crtDateStart", findDateStart);
			}
			if (StringUtils.isNotBlank(findDateEnd)) {
				param.put("crtDateEnd", findDateEnd);
			}
			if (StringUtils.isNotBlank(findPayPlt)) {
				param.put("payPlt", findPayPlt);
			}
			if (StringUtils.isNotBlank(findPayFrom)) {
				param.put("payFrom", findPayFrom);
			}
			if (StringUtils.isNotBlank(findOrderType)) {
				param.put("findOdrType", findOrderType);
			}
			// 默认只检索自己的文档([超级管理员,模版操作员]除外)
			if(!user.isSuperUser() && (user.getRole()&32)!=32) {
				//param.put("user_id", 3);
			}
			//翻页查询
			Page page = orderStatsService.pageOrderStats(param, Integer.parseInt(pageNumber),
					Integer.parseInt(pageSize));
			HashMap<String, Object> resMap = new HashMap<String, Object>();
			resMap.put("total", page.getTotalCount());
			resMap.put("rows", page.getResult());
			mapResult = resMap;
		} else {
			mapResult.clear();
		}
		return SUCCESS;
	}
	
	private String findTestFlg;// 用户属性 测试用户和非测试用户
	//  获取 一键秀 订单统计详情
	//  订单类型   去水印订单[设计]/ 去水印订单[视频]
	public String getYjxOrderCntListinfo() throws Exception{
		// 用户信息
		Map<String, Object> session = ActionContext.getContext().getSession();
		UserInfoDto user = (UserInfoDto)session.get("user");
		if(user!=null && user.getUser_id()!=null) {
			HttpServletRequest request = ServletActionContext.getRequest();
			String pageNumber = request.getParameter("page");
			String pageSize = request.getParameter("rows");
			Map<String, Object> param = new HashMap<String, Object>();
			if(StringUtils.isNotBlank(findOrderDate)&&Long.valueOf(findOrderDate)>0L){
				param.put("findOdt", findOrderDate);
			}
			if (StringUtils.isNotBlank(findDateStart)) {
				param.put("crtDateStart", findDateStart);
			}
			if (StringUtils.isNotBlank(findDateEnd)) {
				param.put("crtDateEnd", findDateEnd);
			}
			if (StringUtils.isNotBlank(findOrderType)) {
				param.put("findOdrType", findOrderType);
			}
			// 默认只检索自己的文档([超级管理员,模版操作员]除外)
			if(!user.isSuperUser() && (user.getRole()&32)!=32) {
				//param.put("user_id", 3);
			}
			if (StringUtils.isNotBlank(findPayPlt)) {
				param.put("payPlt", findPayPlt);
			}
			if (StringUtils.isNotBlank(findPayFrom)) {
				param.put("payFrom", findPayFrom);
			}
			if (StringUtils.isNotEmpty(findTestFlg)){
				param.put("test_flg", findTestFlg);
			}
			
			
			//翻页查询
			Page page = orderStatsService.pageYjxOrderStats(param, Integer.parseInt(pageNumber),
					Integer.parseInt(pageSize));
			HashMap<String, Object> resMap = new HashMap<String, Object>();
			resMap.put("total", page.getTotalCount());
			resMap.put("rows", page.getResult());
			if (mapResult!=null){
				mapResult.clear();
			}
			mapResult = resMap;
		} else {
			mapResult.clear();
		}
		return SUCCESS;
	}
	
	
	/** 
	 * 一键秀 用户统计
	 * 新注册用户数 /  应用模版用户数 / 应用设计模版用户数 /  应用视频模版用户数 / 下单用户数/ 支付金额 /  
	 * @return
	 * @throws Exception
	 */
	public String getStatisUserInfo() throws Exception{
		// 用户信息
		Map<String, Object> session = ActionContext.getContext().getSession();
		UserInfoDto user = (UserInfoDto)session.get("user");
		if(user!=null && user.getUser_id()!=null) {
			HttpServletRequest request = ServletActionContext.getRequest();
			String pageNumber = request.getParameter("page");
			String pageSize = request.getParameter("rows");
			Map<String, Object> param = new HashMap<String, Object>();
			if(StringUtils.isNotBlank(findOrderDate)&&Long.valueOf(findOrderDate)>0L){
				param.put("findOdt", findOrderDate);
			}
			if (StringUtils.isNotBlank(findDateStart)) {
				param.put("crtDateStart", findDateStart);
			}
			if (StringUtils.isNotBlank(findDateEnd)) {
				param.put("crtDateEnd", findDateEnd);
			}
			// 默认只检索自己的文档([超级管理员,模版操作员]除外)
			if(!user.isSuperUser() && (user.getRole()&32)!=32) {
				//param.put("user_id", 3);
			}
			//翻页查询
			Page page = orderStatsService.pageStatisticsUserInfo(param, Integer.parseInt(pageNumber),
					Integer.parseInt(pageSize));
			HashMap<String, Object> resMap = new HashMap<String, Object>();
			resMap.put("total", page.getTotalCount());
			resMap.put("rows", page.getResult());
			if (mapResult!=null){
				mapResult.clear();
			}
			mapResult = resMap;
		} else {
			mapResult.clear();
		}
		return SUCCESS;
	}
	
	

	public String getFindTestFlg() {
		return findTestFlg;
	}
	public void setFindTestFlg(String findTestFlg) {
		this.findTestFlg = findTestFlg;
	}
	public static long getSerialversionuid() {
		return serialVersionUID;
	}
	public String getFindDateStart() {
		return findDateStart;
	}

	public String getFindDateEnd() {
		return findDateEnd;
	}

	public HashMap<String, Object> getMapResult() {
		return mapResult;
	}

	public void setFindDateStart(String findDateStart) {
		this.findDateStart = findDateStart;
	}

	public void setFindDateEnd(String findDateEnd) {
		this.findDateEnd = findDateEnd;
	}

	public void setMapResult(HashMap<String, Object> mapResult) {
		this.mapResult = mapResult;
	}

	public OrderStatsService getOrderStatsService() {
		return orderStatsService;
	}

	public void setOrderStatsService(OrderStatsService orderStatsService) {
		this.orderStatsService = orderStatsService;
	}

	public String getFindOrderDate() {
		return findOrderDate;
	}

	public void setFindOrderDate(String findOrderDate) {
		this.findOrderDate = findOrderDate;
	}

	public String getFindOrderType() {
		return findOrderType;
	}

	public void setFindOrderType(String findOrderType) {
		this.findOrderType = findOrderType;
	}

	public String getFindPayPlt() {
		return findPayPlt;
	}

	public void setFindPayPlt(String findPayPlt) {
		this.findPayPlt = findPayPlt;
	}
	public String getFindPayFrom() {
		return findPayFrom;
	}
	public void setFindPayFrom(String findPayFrom) {
		this.findPayFrom = findPayFrom;
	}
}
